package io.characterStream.fileRorW;

import java.io.UnsupportedEncodingException;
import java.util.Arrays;

/*
编码：字符转字节
    getBytes：给参数可以指定，默认是平台的字符编码
解码：字节转字符

 */
public class StringDemo {
    public static void main(String[] args) throws UnsupportedEncodingException {
        String s = "你好,你好";
        byte[] bytes = s.getBytes();
        System.out.println(Arrays.toString(bytes));

        byte[] gbks = s.getBytes("gbk");
        System.out.println(Arrays.toString(gbks));
        //解码
        byte[] utf8Bytes = {-28, -67, -96, -27, -91, -67, 44, -28, -67, -96, -27, -91, -67};
        byte[] gbkBytes = {-60, -29, -70, -61, 44, -60, -29, -70, -61};
        String s1 = new String(utf8Bytes);
        System.out.println(s1);
        String s2 = new String(gbkBytes,"gbk");
        System.out.println(s2);
    }
}
